package cn.edu.scau.cmi.wuyihan.client;

import cn.edu.scau.cmi.wuyihan.factory.BeefMeatFactory;
import cn.edu.scau.cmi.wuyihan.factory.ChickenMeatFactory;
import cn.edu.scau.cmi.wuyihan.factory.MeatFactory;
import cn.edu.scau.cmi.wuyihan.factory.PorkMeatFactory;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class FactoryClient extends Application{

	@Override
	public void start(Stage primaryStage) throws Exception {
		
		primaryStage.setTitle("Factory");
		GridPane grid = new GridPane();
		grid.setAlignment(Pos.CENTER);
		grid.setHgap(10);
		grid.setVgap(10);
		grid.setPadding(new Insets(25, 25, 25, 25));

		Text title = new Text("Factory");
		title.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));

		 Label pwd = new Label("meat:");
		 ComboBox<String> cb1 = new ComboBox<String>();
		 cb1.getItems().addAll("Beef","Pork","Chicken");
		 cb1.setEditable(true);      
		 cb1.setPrefWidth(200);

		Button confirm = new Button("confirm");

		grid.add(title, 0, 0, 2, 1);

		grid.add(pwd, 0, 2);

		grid.add(cb1, 1, 2);
		
		TextField text = new TextField();
		grid.add(new Label("product"), 0, 3);
		grid.add(text, 1, 3);

		HBox panel = new HBox(40);
		panel.setAlignment(Pos.BOTTOM_RIGHT);
		panel.getChildren().add(confirm);

		HBox panel2 = new HBox(40);
		panel2.setAlignment(Pos.BOTTOM_RIGHT);

		grid.add(panel, 1, 4);
		grid.add(panel2, 1, 5);

		HBox panel3 = new HBox(20);
		panel3.setAlignment(Pos.BOTTOM_RIGHT);
		grid.add(panel3, 1, 6);
		primaryStage.setScene(new Scene(grid, 350, 300));
		
		confirm.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent event) {
				// TODO Auto-generated method stub
				String meatName = cb1.getValue();
				MeatFactory meatFactory = null;
				
				switch (meatName) {
				case "Beef":
					meatFactory = new BeefMeatFactory();
					break;
				case "Chicken":
					meatFactory = new ChickenMeatFactory();
					break;
				case "Pork":
					meatFactory = new PorkMeatFactory();
					break;
				}
				text.setText(meatFactory.getMeat().cook());
			}
		});

		primaryStage.show();	
	}

	public static void main(String[] args) {
		Application.launch(args);
	}
}
